<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('扣减箱数')"/>

<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
                <form id="form1" class="layui-form layui-form-pane" action="">
                    <div class="step-content" id="simplewizardinwidget-steps">
                        <div class="step-pane active" id="simplewizardinwidgetstep1">
                            <div>&nbsp;</div>
                            <input type="hidden" name="id">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">箱数</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="sl" name="sl" placeholder="箱数"
                                               lay-verify="required|number|validateMoney"
                                               autocomplete="off" class="layui-input "/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" data-title>原因</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="xgyy" placeholder="原因" autocomplete="off"
                                               lay-verify="required" class="layui-input "/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" jq-filter="submit" lay-submit=""
                                            lay-filter="addBoxNumber">
                                        立即提交
                                    </button>
                                  <!--  <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                                </div>
                            </div>
                        </div>
                        <input type="hidden" th:value="${id}" id="kid">
                        <input type="hidden" id="xs" name="xs">
                    </div>
                </form>
            </section>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>

<script th:inline="javascript">
    $(function () {

    })

</script>
<script>
    layui.use(['myform', 'zzpUtils', 'form', 'jquery'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils,
            $ = layui.jquery;
        var ids = $("#kid").val();
        zzpUtils.action({
            url: "/wmsturnoverbox/getWmsTurnoverBox",
            data: JSON.stringify({id: ids}),
            success: function (data) {
                zzpUtils.loadJsonDataToForm(data);
            }, error: function (xhr, textStatus) {
                console.log(textStatus);
                console.log(xhr)
            }
        });
        //自定义验证规则-只能输入数字
        form.verify({
            validateMoney: function (value) {
                if (value != '') {
                    if (!/^\d+$/.test(value)) {
                        return '只能填写数字';
                    }
                }
            }
        });
        form.on("submit(addBoxNumber)", function (data) {
            var xs = $("#xs").val();//原箱数
            var sl = $("#sl").val();//扣减箱数
            zzpUtils.confirm("是否确定扣减箱数", function (index) {
                    if (Number(sl) >Number(xs)) {
                        layer.msg("扣减箱数不能大于原箱数："+xs);
                    }else if(Number(sl)==0){
                        layer.msg("扣减箱数不能为0");
                    }else {
                        zzpUtils.action({
                            url: "/wmsturnoverbox/delSl",
                            data: JSON.stringify(data.field),
                            success: function (data) {
                                setTimeout(function () {
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index); //再执行关闭
                                    if(data.type=='success'){
                                        top.layer.msg(data.title);
                                    }else{
                                        top.layer.msg(data.message);
                                    }
                                }, 500);
                            }, error: function (xhr, textStatus) {
                                console.log(textStatus);
                                console.log(xhr);
                            }
                        })
                    }
                }
            )
            return false;
        });
    })
    ;
</script>
</html>